<%@ page import="org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils; com.the8thfold.anton.ant.AntJobUser; com.the8thfold.anton.ant.AntScriptUser; com.the8thfold.anton.users.Roles; com.the8thfold.anton.users.User; com.the8thfold.anton.ant.AntJobRunResults; com.the8thfold.anton.ant.AntJob; com.the8thfold.anton.ant.AntScript" %>
<!DOCTYPE html>
<html>
<head>
    <title><g:layoutTitle default="Home" /> * ANTON</title>
    <link rel="shortcut icon" href="${resource(dir:'images',file:'favicon.ico')}" type="image/x-icon" />

    <g:javascript library="jquery-1.5.1.min"/>
    <g:javascript library="jquery-ui-1.8.12.custom.min"/>
    <g:javascript library="jquery.dataTables"/>

    <link rel="stylesheet" href="${resource(dir:'css',file:'main.css')}" />
    <link rel="stylesheet" href="${resource(dir:'js/colorbox',file:'colorbox.css')}" />
    <link rel="stylesheet" href="${resource(dir:'css/anton',file:'jquery-ui-1.8.12.custom.css')}" type="text/css" />

    <g:javascript library="colorbox/jquery.colorbox" />
    <g:javascript library="application" />

    <script>
        var editor;
        $(document).ready(function(){
            try {
                //Examples of how to assign the ColorBox event to elements
                $(".inline-popupFull").colorbox({
                    returnFocus: false,
                    width:"85%",
                    height:"85%",
                    inline:true,
                    href:"#source",
                    onComplete:function(){
                        if (!editor) {
                            editor = CodeMirror.fromTextArea(document.getElementById("code"),
                            {mode: {name: "xml", htmlMode: false}, lineNumbers: true, readOnly: true});
                        }
                    }
                });
                $(".inline-popup").colorbox({
                    returnFocus: false,
                    maxWidth:"85%",
                    maxHeight:"85%",
                    inline:true,
                    href:"#source",
                    onComplete:function(){
                        if (!editor) {
                            editor = CodeMirror.fromTextArea(document.getElementById("code"),
                            {mode: {name: "xml", htmlMode: false}, lineNumbers: true, readOnly: true});
                        }
                    }
                });

                $(".popup-remote").colorbox({
                    returnFocus: false,
                    photo: false,
                    maxWidth:"85%",
                    maxHeight:"85%",
                    onComplete:function(){
                        $.colorbox.resize();
                    }
                });

                $("#loginButton").button({});
                $("#logoutButton").button();

                //$(".btn").button();
                $(".btn").each(function(item){
                    icon = $(this).attr("icon");
                    $(this).button({icons: {
                        primary: icon
                    },text: false});
                });

                $(".btn-text").button();

                $(".toolbar").buttonset();
                $(".hidden").hide();

            } catch (e) {alert(e);}
        });
    </script>

    <g:layoutHead />
</head>
<body>
<div id="spinner" class="spinner" style="display:none;">
    <img src="${resource(dir:'images',file:'spinner.gif')}" alt="${message(code:'spinner.alt',default:'Loading...')}" />
</div>
%{--<div id="grailsLogo"><a href="http://grails.org"><img src="${resource(dir:'images',file:'grails_logo.png')}" alt="Grails" border="0" /></a></div>--}%
<div id="body">
    <div style="margin: 10px; border-bottom: 1px solid #d3d3d3;">
        <span id="a" style="float: right; margin-right: 40px;">
            <sec:ifLoggedIn>
                Hello
                <a href="${createLink(controller: 'account', action: ".", id: sec.loggedInUserInfo(field: 'userId',''))}"><sec:loggedInUserInfo field="fullName"/></a>
                | <a href="${createLink(controller: 'logout')}" id="logoutButton">Logout</a>
            </sec:ifLoggedIn>
            <sec:ifNotLoggedIn>
                <a href="${createLink(controller: 'login')}" id="loginButton">Login</a>
            </sec:ifNotLoggedIn>
        </span>
        <h1 style="padding: 0 10px; font-weight: bold; font-size: 2.2em;"><a href="/anton"><img style="width: 152px;" src="${resource(dir:'images',file:'anton2.png')}"/> </a></h1>

    </div>
    <div id="nav" class="homePagePanel">
        <div class="ui-widget-content ui-corner-all" style="padding: 15px;  ">
            <div class="css_middle">
                 <ul><li><a href="${createLink(url: request.contextPath)}">Dashboard</a></li>
                    <sec:ifAllGranted roles="${Roles.ROLE_SCRIPT_ADMIN.toString()}">
                        <li><a href="${createLink(controller: 'script', action: 'list')}">Scripts</a>
                            <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_ADMIN.toString())}">
                                <i>(${AntScript.count()})</i>
                            </g:if>
                            <g:else>
                                <i>(${AntScriptUser.countByUser(User.findByUserId(sec.loggedInUserInfo(field: 'userId')))})</i>
                            </g:else>
                        </li>
                    </sec:ifAllGranted>
                    <sec:ifAllGranted roles="${Roles.ROLE_JOB_RUN.toString()}">
                        <li><a href="${createLink(controller: 'job', action: 'list')}">Jobs</a>
                            <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_ADMIN.toString())}">
                                <i>(${AntJob.count()})</i>
                            </g:if>
                            <g:else>
                                <i>(${AntJobUser.countByUser(User.findByUserId(sec.loggedInUserInfo(field: 'userId')))})</i>
                            </g:else>
                        </li>
                    </sec:ifAllGranted>
                    <sec:ifAllGranted roles="${Roles.ROLE_RESULTS_VIEW.toString()}">
                        <li><a href="${createLink(controller: 'result', action: 'list')}">Results</a>
                            <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_ADMIN.toString())}">
                                <i>(${AntJobRunResults.count()})</i>
                            </g:if>
                            <g:else>
                                <i>(${AntJobRunResults.countVisibleByUser(sec.loggedInUserInfo(field: 'userId').toString())})</i>
                            </g:else>
                        </li>
                    </sec:ifAllGranted>

                <sec:ifAllGranted roles="ROLE_ADMIN">

                        <li><a href="${createLink(controller: 'account', action: 'list')}">Users</a> <i>(${User.count()})</i></li>
                        <li><a href="${createLink(controller: 'settings', action: 'list')}">Configuration</a></li>
                    </ul>
                </sec:ifAllGranted>
            </div>
        </div>
    </div>

    <div id="pageBody">
        <br/>
        <g:layoutBody />
    </div>
</div>
</body>
</html>